const renewalService = require('../service/renewalService')
const code = require('../common/code')
const auth = require('../middleware/auth')
const KoaRouter = require('koa-router')

const router = new KoaRouter()

//专柜磅秤续租
router.post('/renewal', auth(['AD']), async ctx => {
    const renewal = ctx.request.body
    renewal.date = new Date()
    ctx.body = code.getCode(code.SUCCESS, null, await renewalService.insert(renewal))
})

router.get('/renewalList/:id', auth(['AD', 'EDP']), async ctx => {
    ctx.body = code.getCode(code.SUCCESS, null, await renewalService.getAllByCounterId(ctx.params.id, ctx.session.user.store_id))
})

router.put('/renewal/:id', auth(['AD']), async ctx => {
    await renewalService.update(ctx.params.id, ctx.request.body.month)
    ctx.body = code.getCode(code.SUCCESS)
})

router.delete('/renewal/:id', auth(['AD']), async ctx => {
    await renewalService.del(ctx.params.id)
    ctx.body = code.getCode(code.SUCCESS)
})

module.exports = router
